<?php

// The $action variable is inherited from index.php

switch ($action) {
case 'courses':
	// Courses template is supposed to use the $course_list array returned from
	// getCourseList
	$course_list = $courses->getCourseList();
	require_once('templates/courses.php');
	break;
case 'getCourse':
	$course_id = $_GET['course'];
	if (strlen($course_id) > 0) {
		$course = $courses->getCourse($course_id);
		echo "<br />\nKursnamn: {$course['name']}<br />\n";
		echo "Målsättning: {$course['goal']}<br />\n";
		if (isset($course['page'])) {
			echo "Kurssida: <a href=\"{$course['page']}\">{$course['page']}</a><br />\n";
		}
		echo "Tidpunkt: {$course['time']}<br />\n";
		echo "Studiepoäng: {$course['sp']}<br />\n";
	}
	else {
		echo "No course given.";
	}
	break;
case 'searchExam':
	break;
case 'searchCourse':
	break;
case 'exams':
	// Exams template is supposed to use the $exams array returned from
	// getExaminationList
	$exams = $courses->getExaminationList();
	require_once('templates/exams.php');
	break;
case 'registerCourse':
	break;
case 'removeCourse':
	if (isset($_GET['page']) && isset($_GET['row'])) {
		$page = $_GET['page'];
		$row  = $_GET['row'];
		$courses->removeCourse($page, $row);
		echo "Kursen har tagits bort";
	}
	$course_list = $courses->getCourseList();
	require_once('templates/courses.php');
	break;
case 'removeExam':
	$row = $_GET['row'];
	$courses->removeExamination($row);
	echo "Removed exam";
	$exams = $courses->getExaminationList();
	require_once('templates/exams.php');
	break;
case 'dropExam':
	$row = $_GET['row'];
	$courses->dropExamination($row);
	echo "Unregistered exam";
	$exams = $courses->getExaminationList();
	require_once('templates/exams.php');
	break;
case 'enrollExam':
	$row = $_GET['row'];
	$courses->enrollExamination($row);
	echo "Enrolled exam";
	$exams = $courses->getExaminationList();
	require_once('templates/exams.php');
	break;
case 'studyPlan':
	echo utf8_encode($page_handler->studyPlan());
	break;
case 'search':
	require_once('templates/search_fields.php');
	
	if (isset($_POST['searchF']) && !isset($_POST['exams']) || isset($_POST['Sall']) || isset($_POST['courses'])) {
		echo "<br/>Kurser: <br/>";
		$results = $courses->searchCoursesOrExams('course');
		require('templates/search.php');
	}
	
	if (isset($_POST['courses']) && isset($_POST['exams']) || isset($_POST['Sall'])) echo "<br/><br/>";
	
	if (isset($_POST['exams']) || isset($_POST['Sall'])) {
		echo "Tenter: <br/>";
		$courses->searchExaminations();
		$results = $courses->searchCoursesOrExams('exams');
		require('templates/search.php');
	}

	break;
case 'addExam':
	echo $page_handler->getCurrentPage();
	$page_handler->addExamination($_GET['row']);
break;
case 'help':
	require_once('templates/help.php');
	break;
default:
	break;
}

